package com.guaju.yueshangLife.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.base.BaseFragmentActivity;
import com.guaju.yueshangLife.fragment.CartFragment;
import com.guaju.yueshangLife.net.NetworkUtil;

public class CartActivity extends BaseFragmentActivity {
    private static final String TAG = "CartActivity";
    CartFragment cartFragment;
    private FragmentManager fm;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cart);

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (NetworkUtil.isConnected(CartActivity.this)) {
            init();
        } else {
            showNetError();
        }
    }

    private void init() {
        cartFragment = new CartFragment();
        fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.fl, cartFragment, TAG);
        ft.commit();
    }

    @Override
    public void onBackPressed() {
        if (cartFragment != null) {
            FragmentTransaction ft = fm.beginTransaction();
            ft.remove(cartFragment);
            ft.commit();
            cartFragment.onDestroy();
            cartFragment = null;
        }
        finish();

    }
}
